SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



ALTER   function f_getallqty
(
  @productid int,
  @unit1qty numeric(18,8),
  @unit2qty numeric(18,8),
  @unit3qty numeric(18,8)
)
returns nvarchar(200)
as  
begin 
  declare @returnvalue nvarchar(200)
  declare @UnitName nvarchar(60)
  declare @uno int
  set @returnvalue = ''
  declare curunit cursor for 
    select unitname,u_no from td_unitprice where 
           productid=@productid and u_no>0 order by u_no
  open curunit
  fetch next from curunit into @unitname,@uno
  while @@fetch_status = 0
  begin
    if (@unitname is null) set @unitname = ''
    if (@uno = 1) and (@unit1qty<>0)
      set @returnvalue=@returnvalue + dbo.f_float_trim(@unit1qty,5) + @unitname
    else if (@uno = 2) and (@unit2qty<>0)
      set @returnvalue=@returnvalue + dbo.f_float_trim(@unit2qty,5) + @unitname
    else if (@uno = 3) and (@unit3qty<>0)
      set @returnvalue=@returnvalue + dbo.f_float_trim(@unit3qty,5) + @unitname
 
    fetch next from curunit into @unitname,@uno
  end
  close curunit
  deallocate curunit
  return @returnvalue
end










GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

